package com.itqf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itqf.entity.DingDan;
import com.itqf.entity.Product;
import com.itqf.mapper.DingDanDao;
import com.itqf.service.DingDanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: Panjianwei
 * @date: 2019/12/18 21:59
 * 代码是一门艺术，需要我们细细用心品味！
 */
@Service
public class DingDanServiceImpl implements DingDanService {
    @Autowired
  private   DingDanDao dingDanDao;
    @Override
    public PageInfo<DingDan> findall(int pageindex, int pagesize, String dUsername, String proName, int Status) {
        Map map = new HashMap<>();
        map.put("dUsername",dUsername);
        map.put("proName",proName);
        map.put("Status",Status);
//        1.指定分页参数
        PageHelper.startPage(pageindex,pagesize);
//        2.调用查询方法
        List<DingDan> findall = dingDanDao.findall(map);
        for (DingDan dingDan : findall) {
            float v = Float.parseFloat(dingDan.getProduct().getProPrice());
            Integer dNumber = dingDan.getDNumber();
            Float sum=v*dNumber;
            dingDan.setMoney(sum);
        }
//        3.结果集封装
        PageInfo<DingDan> pageInfo = new PageInfo(findall);
        return pageInfo;
    }

    @Override
    public int insert(DingDan dingDan) {
        return dingDanDao.insert(dingDan);
    }

    @Override
    public List<Product> findallProduct() {
        return dingDanDao.findallProduct();
    }

    @Override
    public DingDan findbyGid(int dId) {
        return dingDanDao.findbyGid(dId);
    }

    @Override
    public int update(DingDan dingDan) {
        return dingDanDao.update(dingDan);
    }

    @Override
    public int delete(int dId) {
        return dingDanDao.delete(dId);
    }
}
